#include <stdio.h>
#include <map>
#include <string>
using namespace std;

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))

int dist[14][14];
map<string, int> note;
int m, t;
char mel[100010][5];
char piece[10010][5];
char tmp[5];
int dmel[100010];
int dpie[10010];
int pi[100010];
int tamM, tamP;
int k;

void computePrefix() {
	pi[1]=0;
	k=0;

	for (int q=2; q<=tamP; q++) {
		while (k>0 && dpie[k+1] != dpie[q])
			k=pi[k];
		if (dpie[k+1]==dpie[q]) k++;
		pi[q]=k;
	}
}

int kmp() {
	tamM = m-1;
	tamP = t-1;
	int q=0;

	computePrefix();

	for (int i=1; i<=tamM; i++) {
		while (q>0 && dpie[q+1]!=dmel[i])
			q=pi[q];

		if (dpie[q+1]==dmel[i]) q++;
		if (q==tamP) {
			return i-tamP;
		}
	}

	return -1;
}

int main() {
	note["A"]=0;
	note["A#"]=note["Bb"]=1;
	note["B"]=note["Cb"]=2;
	note["C"]=note["B#"]=3;
	note["C#"]=note["Db"]=4;
	note["D"]=5;
	note["Eb"]=note["D#"]=6;
	note["E"]=note["Fb"]=7;
	note["F"]=note["E#"]=8;
	note["F#"]=note["Gb"]=9;
	note["G"]=10;
	note["G#"]=note["Ab"]=11;

	for (int i=0; i<12; i++) dist[i][i]=0;

	for (int i=0; i<12; i++) {
		for (int j=0; j<11; j++)
			dist[i][(i+j+1)%12]=dist[i][(i+j)%12]+1;
	}

	TRACE(
			for (int i=0; i<12; i++) {
			for (int j=0; j<12; j++)
			printf("%2d ", dist[i][j]);
			printf("\n");
			}

	     )

		while (1) {
			scanf("%d %d", &m, &t);

			if (!m && !t) break;

			for (int i=0; i<m; i++)
				scanf(" %s", mel[i]);

			for (int i=0; i<t; i++)
				scanf(" %s", piece[i]);		

			for (int i=1; i<m; i++) 
				dmel[i]=dist[note[mel[i-1]]][note[mel[i]]];
			for (int i=1; i<t; i++) 
				dpie[i]=dist[note[piece[i-1]]][note[piece[i]]];

			TRACE(
					for (int i=0; i<(m-1); i++)
					printf("%d ", dmel[i]);
					printf("\n");

					for (int i=0; i<(t-1); i++)
					printf("%d ", dpie[i]);
					printf("\n");
			     )

			if (kmp()==-1) printf("N\n");
			else printf("S\n");
		}

	return 0;
}
